
package com.eshore.ezone.utils;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class IOUtils {
    private static final String NL = System.getProperty("line.separator");

    public static String stream2String(final InputStream instream) throws IOException {
        final BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
        final StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + NL);
        }
        return sb.toString();
    }

    public static void closeStream(Closeable stream) throws IOException {
        if (stream != null) {
            stream.close();
        }
    }
}
